#' 多变量森林图
#'
#' @param df mv_res_all
#' @param exposure_order exposure的顺序
#' @param pal_color 调色板
#'
#' @return 森林图
#' @export
#'
#' @examples
#'
#' \dontrun{
#'
#' library(Oneclick)
#'
#' M6_forest_plot(mv_res_all)
#'
#' }
#'
#'
M6_forest_plot<-function( df = mv_res_all ,exposure_order = "", pal_color= ggsci::pal_frontiers("default")(10) ){

  require(ggplot2)

  plot_exposure <- function(df, exposure,single_color ){
    # 选取当前Outcome的数据
    df_subset = df[df$exposure == exposure, ]

    # 绘制图形
    p <- ggplot(df_subset, aes(x = or, y = method)) +
      geom_vline(xintercept = 1, linetype = 2) +
      geom_errorbarh(aes(xmin = or_lci95, xmax = or_uci95), height = 0.2,color = single_color) +
      geom_point(size = 3,color = single_color) +
      labs(x = "Odds Ratio", y = "method", title = exposure) +
      theme_minimal()

    return(p)
  }

  if(exposure_order == "" ){
    exposure_order<-unique(df$exposure)
  }

  plots_list<-list()

  for (i in 1:length(exposure_order) ) {
    plots_list[[i]]<- plot_exposure(df,exposure_order[i],pal_color[i])
  }
  p_all<- do.call(gridExtra::grid.arrange,plots_list )
  return(p_all)
}
